<?php

	class class_tinnhan extends class_manage
	{
		
		// Load template with input
		public function gui_tin_nhan($input)
		{	
			$query = 'INSERT INTO `tin_nhan` (
								`id` ,
								`tieude`,
								`noi_dung` ,
								`user_nhan` ,
								`user_gui`,
								`tinh_trang`
									)
						VALUES ("';
			$tstring = implode('","' , $input);
			$query.=$tstring.'")';
			echo $query;
			$this->data->query($query);
			return true;
		}
		public function doc_tin_nhan($id)
		{	
			$query = 'SELECT * FROM `tin_nhan` WHERE `id`='.$id;
			$row=$this->data->query($query)->fetch_assoc();
			$user_info = $this->load('class_member')->user_info('user_id');
			$user_id=$user_info['user_id'];
			if($user_id==$row['user_nhan'] or $id_user==$row['user_gui']){
				return $row;
			}
		}

		//0 la tin nhan da nhan duoc, 1 la tin nhan da gui
		public function list_tin_nhan($page,$result,$type){
			$user_info = $this->load('class_member')->user_info('user_id');
			$user_id=$user_info['user_id'];
			if($type==0){
				$sql='SELECT * FROM `tin_nhan` WHERE `user_nhan`=$user_id  LIMIT ($page-1)*$result,$result';
				}
			if($type==1){
				$sql='SELECT * FROM `tin_nhan` WHERE `user_gui`=$user_id  LIMIT ($page-1)*$result,$result';
			}
			return $this->template->template_replace('list_tin_nhan',$this->data->query($sql)->fetch_assoc());

		}	
	}
	
?>